package com.sinodata.bsm.cicp.collector.net.trap;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;

import org.apache.log4j.Logger;

import com.sinodata.bsm.cicp.util.SystemContext;

public class EventSent {
    private Logger logger = Logger.getLogger(EventSent.class.getName());

    public boolean sendEvent(String event) {
        Socket socket = null;
        PrintWriter os = null;
        String ip = (String) SystemContext.getProperty("CenterIp");
        int port = (Integer) SystemContext.getProperty("EventSentPort");
        try {
            socket = new Socket(ip, port);
            os = new PrintWriter(socket.getOutputStream(), true);
            String readline;
            readline = event;
            os.println(readline);
            // os.flush();
            Thread.sleep(10000);
        } catch (Exception e) {
            logger.error(e);
        } finally {
            // 关闭Socket
            try {
                os.close();
                socket.close();
            } catch (IOException e) {
                logger.error("" + e.getMessage(), e);
            }
        }
        return true;
    }

}
